home *** CD-ROM | disk | FTP | other *** search
- #include "7plus.h"
- #include "globals.h"
-
- int rebuild (char *line, int flag)
- {
- char buf[100], *p;
- uint cs1, cs2, _cs1, _cs2, xcrc;
- int czeile, cflag, len, sw, i, j, k, end, end2, count;
-
- p = buf;
-
- sw = cflag = count = 0;
- _cs1 = _cs2 = xcrc = 0;
-
- len = (int) strlen (line);
-
- end2 = 216;
- end = -1;
-
- if (len == 69)
- sw = 1;
-
- if (len == 70)
- sw = 2;
-
- if (len == 71)
- {
- end = -2;
- end2 = 1;
- sw = 4;
- }
- if (!sw)
- return (0);
-
- /* Try each character in line */
- for (j=66;j>end;j--)
- {
- fflush (stdout);
- if (sw == 1)
- {
- if (j)
- strncpy (p, line, j);
- strncpy (p+j+1, line+j, 71-j);
- p[71] = EOS;
- }
- if (sw == 2)
- strcpy (buf, line);
-
- if (sw == 4)
- {
- strcpy (p, line);
- strncpy (p+j+1, line+j+2, 70-j);
- p[71] = EOS;
- }
-
- if (!cflag)
- {
- crc2 (&_cs1, p);
- cflag++;
- }
-
- if (j<66)
- xcrc = crctab[xcrc>>8] ^ (((xcrc&255)<<8) | (byte)p[j+1]);
-
- for (k=0;k<end2;k++)
- {
- count++;
- if (sw & 3)
- p[j] = code[k];
-
- if (sw == 4)
- {
- cs1 = 0;
- for (i=66; i>-1;i--)
- cs1 = crctab[cs1>>8] ^ (((cs1&255)<<8) | (byte)p[i]);
- }
- else
- {
- cs1 = xcrc;
- for (i=j; i>-1;i--)
- cs1 = crctab[cs1>>8] ^ (((cs1&255)<<8) | (byte)p[i]);
- }
-
- if (_cs1 == (cs1 & 0x7fff))
- {
- if (!flag)
- {
- /* Get line number and crc from code line */
- crc_n_lnum (&_cs2, &czeile, p);
- cs2 = 0;
- for (i=0; i<64; i++)
- cs2 = crctab[cs2>>8] ^ (((cs2&255)<<8) | (byte)p[i]);
- cs2 &= 0x3fff; /* strip calculated CRC to 14 bits */
- }
- else
- if (!mcrc(p, 0))
- continue;
- else
- _cs2 = cs2 = 0;
-
- if (_cs2 == cs2)
- {
- strcpy (line, buf);
- if (flag)
- printf ("\n\nHeader rebuilt. ");
- else
- printf ("\n\t\tLine %03d rebuilt. ", czeile);
- printf ("%5d combinations tested", count);
- if (flag)
- printf ("\n");
- fflush (stdout);
- return (1);
- }
- }
- }
- }
- return (0);
- }
-